package symbolexp;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Logger;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;

public class PairGUI extends JPanel implements ActionListener {

	final static Logger logger = Logger.getLogger(PairGUI.class.getName());

	Pair pr;
	PairImageGUI im;
	String question;
	JButton yesButt;
	JButton noButt;

	Timer showFirst;
	Timer hideFirst;
	Timer showSecond;
	Timer hideSecond;

	int pauseBeforeShowFirst = 1000;
	int symbolShowTime = 2000;
	int pauseBetweenSymbols = 2000;

	public PairGUI(Pair pr) {
		Dimension size = new Dimension(2000, 2000);
		this.setMinimumSize(size);
		this.setSize(size);
		im = new PairImageGUI(pr);

		question = pr.question;

		init();
		initTimers();
	}

	void initTimers() {
		this.showFirst = new Timer(this.pauseBeforeShowFirst, this);
		this.showFirst.setRepeats(false);
		this.showFirst.start();

		this.hideFirst = new Timer(this.symbolShowTime, this);
		this.hideFirst.setRepeats(false);

		this.showSecond = new Timer(this.pauseBetweenSymbols, this);
		this.showSecond.setRepeats(false);
	}

	void init() {

		yesButt = new JButton("Yes");
		yesButt.addActionListener(this);
		noButt = new JButton("No");
		noButt.addActionListener(this);

		this.setLayout(new BorderLayout());

		this.add(im, BorderLayout.CENTER);

		JPanel bottomStuff = new JPanel();
		bottomStuff.setLayout(new BorderLayout());
		JLabel qGUI = new JLabel(question);
		bottomStuff.add(qGUI, BorderLayout.CENTER);

		JPanel yesNoHolder = new JPanel();
		yesNoHolder.add(yesButt);
		yesNoHolder.add(noButt);

		bottomStuff.add(yesNoHolder, BorderLayout.SOUTH);

		this.add(bottomStuff, BorderLayout.SOUTH);

	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == this.showFirst) {
			logger.info("timer happened");
			this.im.state = PairImageGUI.SymbolState.first;
			this.repaint();
			this.hideFirst.start();
		}

		if (e.getSource() == this.hideFirst) {
			this.im.state = PairImageGUI.SymbolState.none;
			this.repaint();
			this.showSecond.start();
		}

	}

	public static void main(String[] args) {
		JFrame app = new JFrame("PairGUI");
		app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		SymbolExperiment sym = new SymbolExperiment("");

		PairGUI prui = new PairGUI(sym.pairsList.get(0));

		app.add(prui);
		app.pack();
		app.setVisible(true);

	}

}
